package com.suep.data_analysis.controller;

import com.suep.data_analysis.dto.AgentDetailDto;
import com.suep.data_analysis.dto.AgentDto;
import com.suep.data_analysis.service.AgentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@AllArgsConstructor
@RestController
@RequestMapping("api/agents")
public class AgentController {
    private final AgentService agentService;

    @Operation(
            summary = "获取角色列表",
            description = "查询所有角色的基本信息（不含属性和技能详情）",
            responses = {
                    @ApiResponse(responseCode = "200", description = "成功获取角色列表",
                            content = @Content(mediaType = "application/json",
                                    schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = AgentDto.class)))
            }
    )
    @GetMapping
    public ResponseEntity<List<AgentDto>> getAllAgents() {
        List<AgentDto> agents = agentService.getAllAgents();
        return ResponseEntity.ok(agents);
    }

    @Operation(
            summary = "根据ID查询角色详情",
            description = "查询指定角色的完整信息（含属性和技能）",
            parameters = {
                    @Parameter(name = "agentId", description = "角色ID", required = true,
                            examples = @ExampleObject(value = "1299", description = "仪玄角色ID"))
            },
            responses = {
                    @ApiResponse(responseCode = "200", description = "成功获取角色详情",
                            content = @Content(mediaType = "application/json",
                                    schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = AgentDetailDto.class))),
                    @ApiResponse(responseCode = "404", description = "角色不存在", content = @Content)
            }
    )
    @GetMapping("/{agentId}")
    public ResponseEntity<AgentDetailDto> getAgentById(@PathVariable String agentId) {
        AgentDetailDto agent = agentService.getAgentById(agentId);
        if (agent == null) {
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(agent);
    }

    @Operation(
            summary = "搜索角色",
            description = "根据关键词搜索角色（支持名称、职业、阵营等字段）",
            parameters = {
                    @Parameter(name = "keyword", description = "搜索关键词", required = true,
                            examples = @ExampleObject(value = "仪玄", description = "搜索包含'仪玄'的角色"))
            },
            responses = {
                    @ApiResponse(responseCode = "200", description = "成功获取搜索结果",
                            content = @Content(mediaType = "application/json",
                                    schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = AgentDto.class)))
            }
    )
    @GetMapping("/search")
    public ResponseEntity<List<AgentDto>> searchAgents(@RequestParam String keyword) {
        List<AgentDto> result = agentService.searchAgents(keyword);
        return ResponseEntity.ok(result);
    }
}